package a;

import java.io.*;
import java.util.Map;

/**
 * @description:
 * @author: jinzewang
 * @project_name: study-springboot-demo
 * @date: 2022/9/7 17:33
 */
public class Main {
    public static void main(String[] args) throws IOException, IllegalAccessException {
/*        String s = "asdfaafsd";
        System.out.println(s.substring(0, s.length() - 2));*/
/*        //随机数
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 1000));
        System.out.println((int) (Math.random() * 10000));
        String s1 = "[\"\"]";
        if (s1.startsWith("[")) {
            String s3 = s1.substring(1, s1.length() - 1);
            String[] split = s3.split(",");
            for (String s2 : split)
                System.out.println(s2);
        }*/

//        Map map = new HashMap<>();
//        map.put("contactInfo", null);
//        map.put("contactInfo", "");
//        map.put("contactInfo", "ancdaf");
//        System.out.println(map.get("contactInfo"));
        String path = "F:\\ChinaMobile\\yidongbangong\\document\\msisdn_or_iccid.txt";
        File file = new File(path);
//        System.out.println(file.getAbsoluteFile());
        int totalLines = getTotalLines(file.getAbsolutePath(), null);
    }

    static int getTotalLines(String fileName, Map<String, Integer> map) throws IOException, IllegalAccessException {
        BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(fileName))); //使用缓冲区的方法将数据读入到缓冲区中
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("F:\\ChinaMobile\\yidongbangong\\document\\res.txt"));
        LineNumberReader reader = new LineNumberReader(br);
        String s = reader.readLine(); //定义行数
        int lines = 0;
        while (s != null) //确定行数
        {
            char[] charArray = s.toCharArray();
            for (char ch : charArray) {
                if (ch == '|') {
                    String[] split = s.split("\\|");
                    String msisdn_or_iccid = split[0];
                    String provinceName = split[1];
                    String provinceId = split[2];
                    if (msisdn_or_iccid != null && provinceId != null && provinceName != null) {
                        String res = "UPDATE t_ps_pad_order SET card_belong_province_id = '" + provinceId + "', card_belong_province_name = '" + provinceName + "' WHERE msisdn_or_iccid = '" + msisdn_or_iccid + "';";
                        bufferedWriter.write(res);
                        bufferedWriter.newLine();
                        bufferedWriter.flush();
                        lines++;
                        break;
                    }
                }
            }
            s = reader.readLine();
        }
        reader.close();
        bufferedWriter.close();
        br.close();
        System.out.println("\n文件名：" + fileName + "\t该文件总行数：" + lines);
//        log.info("文件名：{}\t该文件总行数：{}", fileName, lines);
        return lines; //返回行数
    }
}
